<?php
class articleModel extends Model{
	private $tbl = 'article';
	private $rule = array(
			'title' => array('required'=>true,'min'=>1,'max'=>120),
			'content' => array('required'=>true),	
			);

	public function __construct(){
		parent::__construct($this->tbl);
	}

	public function get_articles($where="",$order="",$limit=""){
		return $this->where($where)->order($order)->limit($limit)->get_view('artinfo');
	}

	public function count_articles($where=""){
		return $this->where($where)->count();	
	}

	public function get_article($id){
		return $this->where(array("id"=>$id))->get_one();
	}

	public function add($data){
		if( !$this->valid($data, $this->rule) ) return false;
		return $this->value($data)->insert();
	}

	public function del($id){
		if( is_int($id) && intval($id)>0 ){
			return $this->where("id=$id")->delete();
		}	
		return false;
	}
	
	public function edit($id, $data){
		if( empty($id) || !is_int($id) ) return false;
		if( !$this->valid($data, $this->rule) ) return false;
		return $this->where("id=$id")->value($data)->update();		
	}
}
